
<!-- start: Header -->
<div id="user" class="navbar">
    <div class="navbar-inner">
        <div class="container-fluid">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".top-nav.nav-collapse,.sidebar-nav.nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand"><span style="font-size: x-large;"><?php echo $A_CONFIG['backstage_name']; ?></span></a>

            <!-- start: Header Menu -->
            <div class="nav-no-collapse header-nav">
                <ul class="nav pull-right">
                    <!-- start: User Dropdown -->
                    <li class="dropdown">
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="halflings-icon white user"></i> <?php echo $login_username;  ?>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li class="dropdown-menu-title">
                                <span>账号设置</span>
                            </li>
                            <li><a @click="changepassword()"><i class="halflings-icon wrench"></i>密码修改</a></li>
                            <li><a href="login.php?action=loginOut"><i class="halflings-icon off"></i>退出登录</a></li>
                        </ul>
                    </li>
                    <!-- end: User Dropdown -->
                </ul>
            </div>
            <!-- end: Header Menu -->

        </div>
    </div>
<!--弹窗-->
    <div class="modal fade hide" id="pop-changepassword" role="dialog" aria-hidden="true" data-backdrop="false">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    修改密码
                </div>
                <div class="modal-body">

                    <div class="control-group">
                        <label for="pop-set-up-old" class="control-label">原密码</label>
                        <div class="controls">
                            <input type="password" class="form-control" id="pop-old-password"
                                  maxlength="20" autocomplete="off" placeholder="请输入原密码"/>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="pop-set-up-new" class="control-label">新密码</label>
                        <div class="controls">
                            <input type="password" class="form-control" id="pop-new-password"
                                   maxlength="20"  autocomplete="off" placeholder="请输入新密码"/>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="pop-set-up-check" class="control-label">确认密码</label>
                        <div class="controls">
                            <input type="password" class="form-control" id="pop-check-password"
                                   maxlength="20" autocomplete="off" placeholder="请确认新密码"/>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="pop-changepassword-submit"
                            @click="changePasswordSubmit()">确定
                    </button>
                    <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- start: Header -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>

<?php
echo $token_info;
    ?>


var oldPassword = null;
var newPassword = null;
var checkPassword =null;
var username = "<?php echo $login_username; ?>";

var theUser = new Vue({
    el: "#user",
    data: {
        token: token,        //input file 的加密
        time: unixtime       //input file 的加密
    },
    methods: {
        changepassword: function () {
            $("#pop-changepassword").modal();
        },
        changePasswordSubmit: function () {
            var oldp = $("#pop-old-password").val();
            var newp = $("#pop-new-password").val();
            var checkp = $("#pop-check-password").val();

            if (oldp == "" || newp == "" || checkp == "") {
                MyAlert("密码不能为空，请重新输入！");
            } else if (oldp.length < 6 || newp.length < 6 || checkp.length < 6) {
                MyAlert("密码不能小于 6 位，请重新输入！");
            }
            else if (newp != checkp) {
                MyAlert("新密码不一致，请重新输入！")
            }else if(oldp == newp){
                MyAlert("新密码不能与原密码相同，请重新输入！")
            }
            else {
                MyConfirm("确定修改?", function () {
                    $.ajax({
                        url: 'api/login/changepassword.php',
                        type: 'POST',
                        data: {
                            token: token,
                            time: unixtime,
                            oldPassword: oldp,
                            newPassword: newp,
                            // checkPassword: checkp,
                            username:username
                        },
                        dataType: 'JSON',
                        beforeSend: function () {
                            $("#loading-mask").show();
                        },
                        error: function () {
                            $("#loading-mask").hide();
                            alert("请求超时");
                        },
                        success: function (res) {
                            $("#loading-mask").hide();
                            if (res.err == 0) {
                                MyAlert(res.msg, function () {
                                    console.log(123);
                                    window.location.href='login.php?action=loginOut';
                                });
                            } else {
                                MyAlert(res.msg);
                            }
                        }
                    })
                })
            }
        },
    }
});
</script>